<template>
  <el-container>
    <el-main>
      <el-form ref="formRef" :model="form.model" :rules="rules" label-width="80">
        <el-form-item  label="账号" prop="account" >
          <el-input disabled v-model="form.model.account"  placeholder="请输入账号" />
        </el-form-item>
        <el-form-item  label="密码" prop="password" >
          <el-input disabled v-model="form.model.password"  placeholder="请输入密码" />
        </el-form-item>
        <el-form-item  label="系统地址" prop="website">
          <el-input disabled v-model="form.model.website" placeholder="请输入系统地址" />
        </el-form-item>
        <el-form-item label="支付码" prop="pay_qrcode">
          <sa-uploader v-model="form.model.pay_qrcode" fileType="image"></sa-uploader>
        </el-form-item>
      </el-form>
    </el-main>
    <el-footer class="sa-footer--submit">
      <el-button v-auth="'seller.admin.application.details'" type="primary" @click="confirm">确定</el-button>
    </el-footer>
  </el-container>
</template>
<script setup>
  import { reactive, ref, unref, onMounted } from 'vue';
  import { api } from '../info.service';

  

  const emit = defineEmits(['modalCallBack']);
  const props = defineProps(['modal']);

  const formRef = ref();
  const form = reactive({
    model: {
      account:'',
      password:'',
      website:'',
      pay_qrcode:'',
    },
  });

  const rules = reactive({
    account: [
      { required: true, message: '请填写', trigger: 'blur' },
    ],
    password: [
      { required: true, message: '请填写', trigger: 'blur' },
    ],
    website: [
      { required: true, message: '请填写', trigger: 'blur' },
    ],
    
  });

  
  function confirm() {
    unref(formRef).validate(async (valid) => {
      if (!valid) return;
      const { error } = await api.updateAccount(props.modal.params.id, form.model);
      if (error === 0) {
        emit('modalCallBack', { event: 'confirm' });
      }
    });
  }


  onMounted(async () => {
    if (props.modal.params.id) {
      const { error, data } = await api.detail(props.modal.params.id);
      if (error === 0) {
        form.model=JSON.parse(data.ck_result)
      }
      
    }
  });
</script>
